package com.xlh.virtualization.constant;


/**
 * 实验场景枚举
 *
 * @author cheer
 */
public enum ContextTypeEnum {

    COURSE(0, "实验课程"),
    TASK(1, "实验任务"),
    TRAINING(2, "环境实训"),
    QUESTION(3, "考试试题"),
    // 4,5,6 用于区分实验和镜像分配生成的容器
    COURSE_IMAGE_ALLOCATION(4, "实验课程镜像分配"),
    TRAINING_IMAGE_ALLOCATION(5, "环境实训镜像分配"),
    QUESTION_IMAGE_ALLOCATION(6, "考试试题镜像分配");

    private Integer code;
    private String message;

    ContextTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 把制作场景中生成的容器的场景类型 转化为镜像分配的场景类型
     */
    public static Integer toImageAllocation(Integer code) {
        ContextTypeEnum contextTypeEnum = forCode(code);
        if (contextTypeEnum == null) {
            return null;
        }
        if (contextTypeEnum == COURSE_IMAGE_ALLOCATION) {
            return TASK.code;
        }
        if (contextTypeEnum == TRAINING_IMAGE_ALLOCATION) {
            return TRAINING.code;
        }
        if (contextTypeEnum == QUESTION_IMAGE_ALLOCATION) {
            return QUESTION.code;
        }
        return code;
    }

    /**
     * 把制作场景中生成的容器的场景类型 转化为镜像的场景类型
     */
    public static Integer toImage(Integer code) {
        ContextTypeEnum contextTypeEnum = forCode(code);
        if (contextTypeEnum == null) {
            return null;
        }
        if (contextTypeEnum == COURSE_IMAGE_ALLOCATION || contextTypeEnum == QUESTION_IMAGE_ALLOCATION) {
            return TASK.code;
        } else if (contextTypeEnum == TRAINING_IMAGE_ALLOCATION) {
            return TRAINING.code;
        }
        return null;
    }

    public static ContextTypeEnum forCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ContextTypeEnum contextTypeEnum : ContextTypeEnum.values()) {
            if (contextTypeEnum.code.equals(code)) {
                return contextTypeEnum;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

}
